package com.sikadwafastdaisfondturbo.pretloan.adapter

import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaRecyclerViewAdapter
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaViewHolderHelper
import com.sikadwafastdaisfondturbo.pretloan.R
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/19 12:02
 * @Annotation：流程步骤
 */
class ProcessStepAdapter(recyclerView: RecyclerView?): SikadwaRecyclerViewAdapter<JSONObject>(recyclerView,R.layout.item_process_step) {

    override fun setItemChildListener(helper: SikadwaViewHolderHelper, viewType: Int) {
    }

    override fun fillData(helper: SikadwaViewHolderHelper, position: Int, model: JSONObject) {
        val textStep = helper.getTextView(R.id.textStep)
        textStep.text = "${position+1}"
        val textTitle = helper.getTextView(R.id.textTitle)
        textTitle.text = model.optString("tabTitle")

        val selectIndex = model.optInt("selectIndex", 0)
        val startLine = helper.getView<View>(R.id.vStartLine)
        val endLine = helper.getView<View>(R.id.vEndLine)
        val imgCursor = helper.getImageView(R.id.imgCursor)

        if (position < selectIndex){
            imgCursor.visibility = View.INVISIBLE
            textTitle.setTextColor(ContextCompat.getColor(mContext,R.color.black))
            textStep.visibility = View.GONE
            textStep.setBackgroundResource(R.drawable.btn_selector_circle)
            helper.setVisibility(R.id.imgCompleted,View.VISIBLE)
            startLine.setBackgroundColor(ContextCompat.getColor(mContext,R.color.FF4C8FFB))
            endLine.setBackgroundColor(ContextCompat.getColor(mContext,R.color.FF4C8FFB))
        } else if (position == selectIndex){
            imgCursor.visibility = View.VISIBLE
            textTitle.setTextColor(ContextCompat.getColor(mContext,R.color.black))
            textStep.visibility = View.VISIBLE
            textStep.setBackgroundResource(R.drawable.btn_selector_circle)
            helper.setVisibility(R.id.imgCompleted,View.GONE)
            startLine.setBackgroundColor(ContextCompat.getColor(mContext,R.color.FF4C8FFB))
            endLine.setBackgroundColor(ContextCompat.getColor(mContext,R.color.FFE2E2E2))
        } else {
            imgCursor.visibility = View.INVISIBLE
            textTitle.setTextColor(ContextCompat.getColor(mContext,R.color.FF999999))
            textStep.visibility = View.VISIBLE
            textStep.setBackgroundResource(R.drawable.circle_fill_ffe9e9e9)
            helper.setVisibility(R.id.imgCompleted,View.GONE)
            startLine.setBackgroundColor(ContextCompat.getColor(mContext,R.color.FFE2E2E2))
            endLine.setBackgroundColor(ContextCompat.getColor(mContext,R.color.FFE2E2E2))
        }

        if (position == 0){
            startLine.visibility = View.INVISIBLE
            endLine.visibility = View.VISIBLE
        } else if (position == itemCount - 1){
            startLine.visibility = View.VISIBLE
            endLine.visibility = View.INVISIBLE
        } else {
            startLine.visibility = View.VISIBLE
            endLine.visibility = View.VISIBLE
        }
    }
}